jQuery(function($) {
	$(".u-chosen-select").chosen();
	
	user.select.init({
         jobId:$("#job_list_id").val(),
         deptId:$("#dep_list_id").val(),
    });
	
	$( "#datepicker" ).datepicker({
    	language : "zh-CN",
        showOtherMonths: true,
        selectOtherMonths: false,
        format:'yyyy-mm-dd',
        //isRTL:true,
    });
})

var user= {
    select: {
        init:function (params) {
            var jobId = params['jobId'];
            var path=$("#context_hidden_id").val();
            $.ajax({
                type:"get",
                url:path+"/rest/job",
                async:true,
                dataType:"json",
                success:function(result){
                    for (var i=0;i<result.length;i++){
                        var label=result[i].label;
                        var value=result[i].value;
                        if (value==jobId){
                            $("#job-select").append("<option value='"+value+"' selected='selected'>"+label+"</option>")
                        }else{
                        	$("#job-select").append("<option value='"+value+"'>"+label+"</option>")
                        }
                    }
                    $(".job-chosen-select").chosen();
                }
            });
            
            var deptId = params['deptId'];
            $.ajax({
                type:"get",
                url:path+"/rest/dept",
                async:true,
                dataType:"json",
                success:function(result){
                    for (var i=0;i<result.length;i++){
                        var label=result[i].label;
                        var value=result[i].value;
                        if (value==deptId){
                            $("#dept-select").append("<option value='"+value+"' selected='selected'>"+label+"</option>")
                        }else{
                        	$("#dept-select").append("<option value='"+value+"'>"+label+"</option>")
                        }
                    }
                    $(".dept-chosen-select").chosen(); 
                }
            });
        }
    }
}